﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;

namespace TrailMap.Controls
{
    public partial class DrawTool : UserControl
    {

        private MainPage m_mainPage = null;

        public DrawTool()
        {
            InitializeComponent();

            //trackButtons.ItemsSource = new ToolBoxData[] { 
            //    new ToolBoxData{ Image = new BitmapImage(new Uri("/TrailMap;component/Resources/Ml.png", UriKind.Relative)), Label = "Draw Track", Tooltip = "" }, 
            //    new ToolBoxData{ Image = new BitmapImage(new Uri("/TrailMap;component/Resources/Mr.png", UriKind.Relative)), Label = "Draw Along Road", Tooltip = "" },
            //    new ToolBoxData{ Image = new BitmapImage(new Uri("/TrailMap;component/Resources/Mp.png", UriKind.Relative)), Label = "Draw Area", Tooltip = "" } 
            //};
        }

        public void InitializeDrawTool(MainPage mainPage)
        {
            m_mainPage = mainPage;
        }

        public DrawToolSelection CurrentSelection
        {
            get
            {
                DrawToolSelection retVal = DrawToolSelection.Hand;

                switch (trackButtons.SelectedIndex)
                {
                    case 0:
                        retVal = DrawToolSelection.Hand;
                        break;
                    case 1:
                        retVal = DrawToolSelection.Waypoint;
                        break;
                    case 2:
                        retVal = DrawToolSelection.DrawTrackAtBegin;
                        break;
                    case 3:
                        retVal = DrawToolSelection.DrawTrackAtEnd;
                        break;
                }
                return retVal;
            }
        }

        private void trackButtons_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (m_mainPage.DrawTrackCtrl.CurrentEditTrack == null)
            {
                switch (trackButtons.SelectedIndex)
                {
                    case 2:
                    case 3:
                        MessageBox.Show("this feature works on only in edit mode", "Error", MessageBoxButton.OK);
                        trackButtons.SelectedIndex = 0;
                        break;
                }
            }
        }
    }

    public class ToolBoxData
    {
        public ImageSource Image { get; set; }
        public string Label { get; set; }
        public string Tooltip { get; set; }
    }

    public enum DrawToolSelection
    {
        Hand,
        Waypoint,
        DrawTrackAtBegin,
        DrawTrackAtEnd
    }
}
